﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SourceMaster.Util
{
    public class DateUtil
    {
        public static string GetRelative(DateTime dt)
        {
            var ts = new TimeSpan(DateTime.Now.Ticks - dt.Ticks);
            double delta = Math.Abs(ts.TotalSeconds);
            const int SECOND = 1;
            const int MINUTE = 60 * SECOND;
            const int HOUR = 60 * MINUTE;
            const int DAY = 24 * HOUR;

            if(delta < 2 * MINUTE)
            {
                return "One minutes ago";
            }

            if(delta < 45 * MINUTE)
            {
                return ts.Minutes + " minutes ago";
            }

            if(delta < 7 * DAY)
            {
                return ts.Days + " days ago";
            }

            return dt.ToShortDateString() + ' ' + dt.ToShortDateString();
        }
    }
}
